package com.itheima.reggie.mapper;

import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {
    @Select("select count(*) from dish where category_id=#{id} and is_deleted=0")
    Integer selectDish(Long id);

    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description}," +
            "#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer insert(DishDto dishDto);

    List<DishDto> findAll2(@Param("name") String name);

    //分页查询(方式：分表查) ：第一条sql  按照菜品分页查询
    List<Dish> findAll(@Param("name") String name);
    //根据菜品的id查询一个菜品(一个菜品和多个口味)

    DishDto findById(Long id);

    Integer updateById(DishDto dishDto);

    Integer updateStatus(@Param("ids") Long[] ids,@Param("status") Integer status);

    //Integer updateStatus1(@Param("ids") Long[] ids);

    Integer delete(@Param("ids") Long[] ids);

    //根据类别id查询菜品列表的方法
    @Select("select * from dish where category_id=#{categoryId} and is_deleted=0 order by sort asc")
    List<Dish> findByCategoryId(Long categoryId);


//    @Select("select * from dish "+
//    "where category_id = #{categoryId} and is_deleted=0 and status=#{status} "+
//    "order by sort asc")
    List<Dish> findByCategoryIdAndStatus(@Param("categoryId") Long categoryId,@Param("status") Integer status,@Param("name") String name);
}